home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / I-Z / ResExpress 1.0.sea / ResExpress 1.0 / ResX DevKit / Think Pascal / Sound Recorder.p < prev   
Text File  |  1991-07-05  |  5KB  |  135 lines

  1.  
  2. unit Sound_Recorder;
  3.  
  4. {Uses the Sound Input Device.  If using Mac Recorder, the Mac Recorder Driver is necessary}
  5. {to properly work with the Sound Manager.}
  6.  
  7. {Sys7 or Sound Manager libraries for Think Pascal is required to compile this.}
  8. {Build Order for Think Pascal:}
  9. {DRVRRunTime.lib}
  10. {Interface.lib}
  11. {ResX Utils.lib}
  12. {ResX Ulits.p}
  13. {Types.p}
  14. {Traps.p}
  15. {OSUtils.p}
  16. {Files.p}
  17. {Sound.p}
  18. {Dialogs.p}
  19. {Memory.p}
  20. {SoundInput.p}
  21. {Sound Recorder.p}
  22.  
  23. {To compile in Think Pascal:}
  24. {   1) Set Project Type to 'Code Resource' }
  25. {   2) Set the File TYPE to 'RXXT' and File Creator to 'ResX'}
  26. {   3) Set the Resource TYPE to 'RXXT' }
  27. {   4) Set the Resource NAME to 'Sound Recorder'. }
  28. {   5) Add this file, and the above files in the build order to the project }
  29. {   6) Compile the code resource. }
  30. {   7) Install it in ResX via the 'Externals->Install' menu. }
  31.  
  32. interface
  33.     uses
  34.         Types, OSUtils, Dialogs, Files, Sound, SoundInput, Traps, Memory, ResXUtils;
  35.  
  36.  
  37. {TheHandle is the handle that is passed in from ResX of the currently selected resource. }
  38. {It will not be used in this external.}
  39.     procedure main (TheHandle: Handle);
  40. implementation
  41.     procedure main;
  42.         const
  43.             _SoundDispatch = $A800;
  44.         var
  45.             myErr, hndlErr: OSErr;
  46.             chan: SndChannelPtr;
  47.             fileID: integer;
  48.             warning, sTemp: Str255;
  49.             pnt, centerPoint: point;
  50.             Globals: GlobalsPtr;
  51.             SndHandle: Handle;
  52.             HType: Boolean;
  53.  
  54. {Main}
  55. {____________________________________________________}
  56.     begin
  57.         SetResLoad(TRUE);
  58.         Globals := GlobalsPtr(WindowPeek(FrontWindow)^.refCon);    {From ResX Utils}
  59.  
  60.  
  61.     {Make sure a file is opened within ResX before continuing.}
  62.         if not (Globals^.LOpen) and not (Globals^.ROpen) then
  63.             begin
  64.                 OKAlert('A file must be opened within ResX before a sound can be recorded.');                             {From ResX Utils}
  65.                 exit(main);
  66.             end;
  67.  
  68.     {Make sure the Sound Manager is available before continuing.}
  69.         if not TrapAvailable(_SoundDispatch) then
  70.             begin
  71.                 OKAlert('Sound Manager not available.  This external only supports System 6.0.7, System 7.0 or higher.');                             {From ResX Utils}
  72.                 exit(main);
  73.             end;
  74.  
  75.  
  76.     {Center the Sound Recorder Dialog}
  77.         GetCenterPoint(centerPoint);                                               {From ResX Utils}
  78.         SetPt(pnt, centerPoint.h - 150, centerPoint.v - 40);
  79.  
  80.     {Get as much memory as we can.  SuperNewHandle will give us 90% of the}
  81.     {available memory if we request a ridiculously large value.  Never alter HType, }
  82.     {it is necessary to determine how to properly dispose a Super handle.  See ResX}
  83.     {Utils for information on the Super Memory Manager.}
  84.  
  85.         SndHandle := SuperNewHandle($FFFFFF, HType, hndlErr);
  86.         SuperHLock(SndHandle, HType, hndlErr);
  87.  
  88.     {Way cool, we're ready to boogie!  Let's record a sound! }
  89.         myErr := SndRecord(nil, pnt, siGoodQuality, SndHandle);     {Sound Manager or Sys7 Libraries required}
  90.  
  91.         if (myErr <> 0) and (SndHandle <> nil) then        {Do we have a valid sound to save?}
  92.             begin
  93.                 if (myErr <> -128) then                        {Maybe it was the Cancel Button?}
  94.                     begin                                            {Display error message}
  95.                         sTemp := 'Sound Manager error:  ';
  96.                         NumToString(myErr, warning);
  97.                         warning := concat(sTemp, warning);
  98.                         OKAlert(warning);                                     {From ResX Utils}
  99.                     end;
  100.                 SuperHUnLock(SndHandle, HType, hndlErr);
  101.                 SuperDisposHandle(SndHandle, HType, hndlErr);
  102.             end
  103.         else                                                    {We have a valid sound to save}
  104.             begin
  105.                 fileID := SelectFile;                                     {From ResX Utils}
  106.                 if (fileID > 0) then                                {Are we saving to a file opened within ResX?}
  107.                     begin                                            {We have a file to save it to.}
  108.                         UseResFile(fileID);
  109.                         AddResource(SndHandle, 'snd ', Unique1ID('snd '), 'Recorded Sound');
  110.                         if (ResError <> 0) then
  111.                             begin
  112.                                 sTemp := 'Check disk space. Could not add the resource.  Error #';
  113.                                 NumToString(ResError, warning);
  114.                                 warning := concat(sTemp, warning);
  115.                                 OKAlert(warning);                                 {From ResX Utils}
  116.                                 SuperHUnLock(SndHandle, HType, hndlErr);
  117.                                 SuperDisposHandle(SndHandle, HType, hndlErr);
  118.                                 exit(main);
  119.                             end;
  120.                         WriteResource(SndHandle);
  121.                         SuperHUnLock(SndHandle, HType, hndlErr);
  122.                         ReleaseResource(SndHandle);
  123.                     end
  124.                 else                                                {Sound was cancelled with Cancel Button}
  125.                     begin
  126.                         SuperHUnLock(SndHandle, HType, hndlErr);
  127.                         SuperDisposHandle(SndHandle, HType, hndlErr);
  128.                     end;
  129.             end;
  130.  
  131.  
  132. {End of Sound Recorder code.}
  133. {____________________________________________________}
  134.     end;
  135. end.